bitkeeper revision 1.172.2.1 (3e9d99f1bgmrT-dK132TjqTggS_oow)
authoriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Wed, 16 Apr 2003 17:59:13 +0000 (17:59 +0000)
committeriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Wed, 16 Apr 2003 17:59:13 +0000 (17:59 +0000)
Add support to domain_builder to enable domains>0 to be booted with
initrd's (initial ram disks).

To continue the fine tradition of layering hack upon hack in domain_builder,
if the 4th parameter to domain_builder starts 'initrd=' then it will
load the specified file as an initrd module, and pass that to the new kernel.

For example:
r ./newdom 128000 ../../../xenolinux-2.4.21-pre4/arch/xeno/boot/image 128.232.xx.xx initrd=/usr/groups/srgboot/xxx/initrd ip=128.232.xx.xx:128.232.32.20:128.232.32.1:255.255.240.0::eth0:off ramdisk_size=32804 root=/dev/ram0 rw

Someone really needs to rewrite domain_builder to take more sensible command
line arguments...

tools/domain_builder/dom_builder.c
xen/Makefile
xen/common/domain.c
xen/include/xeno/dom0_ops.h
xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h

index 1370c96df5801da2e64001f4366ead7a7fad7843..d2ba7db2c7b5174e7819451903344618dd55bfb8 100644 (file)
@@ -238,7 +238,7 @@ out:
  * manner. this way, many potentially messy things are avoided...
  */ 
 #define PAGE_TO_VADDR(_pfn) ((void *)(dom_mem->vaddr + ((_pfn) * PAGE_SIZE)))
-static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, 
+static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, int initrd_fd,
     unsigned long virt_load_addr, size_t ksize, dom_mem_t *dom_mem)
 {
     dom_meminfo_t *meminfo;
@@ -260,6 +260,8 @@ static dom_meminfo_t *setup_guestos(int dom, int kernel_fd,
     pgt_updates = (page_update_request_t *)dom_mem->vaddr;
     alloc_index = dom_mem->tot_pages - 1;
 
+    memset(meminfo, 0, sizeof(meminfo));
+
     memcpy(page_array, (void *)dom_mem->vaddr, dom_mem->tot_pages * 4);
 
     /* Count bottom-level PTs, rounding up. Include one PTE for shared info. */
@@ -365,6 +367,31 @@ static dom_meminfo_t *setup_guestos(int dom, int kernel_fd,
         goto out;
     }
 
+    if( initrd_fd )
+      {
+       struct stat stat;
+       unsigned long isize;
+
+       if(fstat(initrd_fd, &stat) < 0){
+         perror(PERR_STRING);
+         close(initrd_fd);
+         goto out;
+       }
+       isize = stat.st_size;
+
+       if( read(initrd_fd, ((char *)dom_mem->vaddr)+ksize, isize) != isize )
+         {
+           dberr("Error reading initrd image, could not"
+                 " read the whole image. Terminating.\n");
+           goto out;
+         }
+
+       meminfo->virt_mod_addr = virt_load_addr + ksize;
+       meminfo->virt_mod_len  = isize;
+
+      }
+
+
     ret = meminfo;
 out:
 
@@ -404,16 +431,20 @@ int main(int argc, char **argv)
     size_t ksize;
     unsigned long load_addr;
     char status[1024];
-    int kernel_fd;
+    int kernel_fd, initrd_fd = 0;
     int count;
     int cmd_len;
     int rc = -1;
+    int args_start = 4;
+    char initrd_name[1024];
 
     unsigned long addr;
 
+    /**** this argument parsing code is really _gross_. rewrite me! ****/
+
     if(argc < 4) {
         dberr("Usage: dom_builder <kbytes_mem> <image> <num_vifs> "
-             "<boot_params>\n");
+             "[<initrd=initrd_name>] <boot_params>\n");
         goto out;
     }
 
@@ -434,8 +465,22 @@ int main(int argc, char **argv)
                   dom_data->domain, &dom_os_image))
         goto out;
 
+    if( strncmp("initrd=", argv[args_start], 7) == 0 )
+      {
+       strncpy( initrd_name, argv[args_start]+7, sizeof(initrd_name) );
+       initrd_name[sizeof(initrd_name)-1] = 0;
+       printf("initrd present, name = %s\n", initrd_name );
+       args_start++;
+
+       initrd_fd = open(initrd_name, O_RDONLY);
+       if(initrd_fd < 0){
+         perror(PERR_STRING);
+         goto out;
+       }
+      }
+
     /* the following code does the actual domain building */
-    meminfo = setup_guestos(dom_data->domain, kernel_fd, load_addr, 
+    meminfo = setup_guestos(dom_data->domain, kernel_fd, initrd_fd, load_addr, 
                            ksize, &dom_os_image); 
     
     /* and unmap the new domain's memory image since we no longer need it */
@@ -450,7 +495,7 @@ int main(int argc, char **argv)
     meminfo->num_vifs = atoi(argv[3]);
     meminfo->cmd_line[0] = '\0';
     cmd_len = 0;
-    for(count = 4; count < argc; count++){
+    for(count = args_start; count < argc; count++){
         if(cmd_len + strlen(argv[count]) > MAX_CMD_LEN - 1){
             dberr("Size of image boot params too big!\n");
             break;
index 85e451491939e43cb3c7e1ed2fdbed1f1acd90e0..196ad794428810ad04f983e8e2828181788cf634 100644 (file)
@@ -5,7 +5,9 @@ include Rules.mk
 
 default: $(TARGET)
        gzip -f -9 < $(TARGET) > $(TARGET).gz
-#      objdump -D -S image >image.s
+
+debug: 
+       objdump -D -S image >image.s
 
 install: $(TARGET)
        gzip -f -9 < $(TARGET) > $(TARGET).gz
index 10b96042a7b4ea99d20d4ac1bc6618d515726da6..8b0652f8adf39fef4cb2e7b693cb32f720f294a5 100644 (file)
@@ -323,7 +323,16 @@ int final_setup_guestos(struct task_struct * p, dom_meminfo_t * meminfo)
     virt_startinfo_addr->shared_info = (shared_info_t *)meminfo->virt_shinfo_addr;
     virt_startinfo_addr->pt_base = meminfo->virt_load_addr + 
                     ((p->tot_pages - 1) << PAGE_SHIFT);
-    
+   
+    /* module size and length */
+
+    virt_startinfo_addr->mod_start = meminfo->virt_mod_addr;
+    virt_startinfo_addr->mod_len   = meminfo->virt_mod_len;
+
+       
+    if( virt_startinfo_addr->mod_len )
+       printk("Initrd module present %08x (%08x)\n",virt_startinfo_addr->mod_start, virt_startinfo_addr->mod_len);     
     /* Add virtual network interfaces and point to them in startinfo. */
     while (meminfo->num_vifs-- > 0) {
         net_vif = create_net_vif(p->domain);
index c0159d12cc1cf7851aace2598efcc06d4c882198..ea3f829d731e5081899e51cde07a5f600ee53a38 100644 (file)
@@ -51,6 +51,8 @@ typedef struct domain_launch
     unsigned long virt_startinfo_addr;
     unsigned int num_vifs;
     char cmd_line[MAX_CMD_LEN];
+    unsigned long virt_mod_addr;
+    unsigned long virt_mod_len;
 } dom_meminfo_t;
 
 typedef struct dom0_bvtctl_st
index 22ebd7aba0978b5b88b5ab334bfbc45557c2bb28..74c9b24de74485cdee5dba707566732fe6e414d7 100644 (file)
@@ -81,6 +81,8 @@ typedef struct domain_launch
     unsigned long virt_startinfo_addr;
     unsigned int num_vifs;
     char cmd_line[MAX_CMD_LEN];
+    unsigned long virt_mod_addr;
+    unsigned long virt_mod_len;
 } dom_meminfo_t;